const express = require('express');
const router = express.Router();
const users = require('../data/user');
const pmroutes = require('../data/routerPermission')

router.get('/user',(req,res)=>{
    res.header("Access-Control-Allow-Origin", "*")
    console.log(res.query)
    const username = req.query.username;
    let user = users.find(u=>u.name ===username)

    if(user){
        let userinfo = {
            username :username,
            token: 1213 +username,
        }
        res.send(userinfo)
    }else{
        res.status(403).send('你没有权限')
    }
    

})
router.get('/menu',(req,res)=>{
    res.header("Access-Control-Allow-Origin", "*")
    const username = req.query.username;
    let userinfo=users.filter(user=>user.name == username)
    let authRouterinfo = [];
    userinfo[0].auth.map(a=>{
        pmroutes.map(r=>{
            if(a==r.id){
                r.right = userinfo[0].right;
                authRouterinfo.push(r)
            }
        })
    })
 if(userinfo.length!= 0){
     res.send({
         authData:authRouterinfo
     })
 }else{
     res.status(404).send('查无此人')
 }
})
module.exports = router;